; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc -mtriple=aarch64 -mattr=+sve %s -o - | FileCheck %s

define i64 @scalable_int_min_max(ptr %arg, ptr %arg1, <vscale x 2 x ptr> %i37, <vscale x 2 x i64> %i42, <vscale x 2 x i64> %i54) {
; CHECK-LABEL: scalable_int_min_max:
; CHECK:       // %bb.0: // %entry
; CHECK-NEXT:    ptrue p0.d
; CHECK-NEXT:    mov w8, #3745
; CHECK-NEXT:    movk w8, #16618, lsl #16
; CHECK-NEXT:    ld1w { z3.d }, p0/z, [x0]
; CHECK-NEXT:    mov w9, #57344
; CHECK-NEXT:    mov z6.d, #1023 // =0x3ff
; CHECK-NEXT:    movk w9, #17535, lsl #16
; CHECK-NEXT:    mov z4.s, w8
; CHECK-NEXT:    fmul z4.s, p0/m, z4.s, z3.s
; CHECK-NEXT:    mov z5.s, w9
; CHECK-NEXT:    fadd z4.s, p0/m, z4.s, z5.s
; CHECK-NEXT:    mov z5.d, #0 // =0x0
; CHECK-NEXT:    fcvtzs z4.d, p0/m, z4.s
; CHECK-NEXT:    sxtw z5.d, p0/m, z5.d
; CHECK-NEXT:    smax z4.d, p0/m, z4.d, z5.d
; CHECK-NEXT:    movprfx z5, z6
; CHECK-NEXT:    sxtw z5.d, p0/m, z6.d
; CHECK-NEXT:    smin z4.d, p0/m, z4.d, z5.d
; CHECK-NEXT:    cmpne p1.d, p0/z, z4.d, #0
; CHECK-NEXT:    ld1w { z4.d }, p1/z, [x1]
; CHECK-NEXT:    ld1w { z0.d }, p1/z, [z0.d]
; CHECK-NEXT:    fadd z0.s, p0/m, z0.s, z4.s
; CHECK-NEXT:    fcmge p2.s, p0/z, z0.s, z3.s
; CHECK-NEXT:    bic p2.b, p1/z, p1.b, p2.b
; CHECK-NEXT:    mov z1.d, p2/m, #0 // =0x0
; CHECK-NEXT:    add z2.d, p1/m, z2.d, z1.d
; CHECK-NEXT:    uaddv d0, p0, z2.d
; CHECK-NEXT:    fmov x0, d0
; CHECK-NEXT:    ret
entry:
  %i56 = getelementptr inbounds float, ptr %arg, i64 0
  %i57 = load <vscale x 2 x float>, ptr %i56, align 4
  %i58 = fmul <vscale x 2 x float> %i57, shufflevector (<vscale x 2 x float> insertelement (<vscale x 2 x float> poison, float 0x401D41D420000000, i64 0), <vscale x 2 x float> poison, <vscale x 2 x i32> zeroinitializer)
  %i59 = fadd <vscale x 2 x float> %i58, shufflevector (<vscale x 2 x float> insertelement (<vscale x 2 x float> poison, float 1.023500e+03, i64 0), <vscale x 2 x float> poison, <vscale x 2 x i32> zeroinitializer)
  %i60 = fptosi <vscale x 2 x float> %i59 to <vscale x 2 x i32>
  %i61 = tail call <vscale x 2 x i32> @llvm.smax.nxv2i32(<vscale x 2 x i32> %i60, <vscale x 2 x i32> zeroinitializer)
  %i62 = tail call <vscale x 2 x i32> @llvm.smin.nxv2i32(<vscale x 2 x i32> %i61, <vscale x 2 x i32> shufflevector (<vscale x 2 x i32> insertelement (<vscale x 2 x i32> poison, i32 1023, i64 0), <vscale x 2 x i32> poison, <vscale x 2 x i32> zeroinitializer))
  %i63 = icmp ne <vscale x 2 x i32> %i62, zeroinitializer
  %i64 = getelementptr float, ptr %arg1, i64 0
  %i65 = tail call <vscale x 2 x float> @llvm.masked.load.nxv2f32.p0(ptr %i64, i32 4, <vscale x 2 x i1> %i63, <vscale x 2 x float> poison)
  %i66 = tail call <vscale x 2 x float> @llvm.masked.gather.nxv2f32.nxv2p0(<vscale x 2 x ptr> %i37, i32 4, <vscale x 2 x i1> %i63, <vscale x 2 x float> poison)
  %i67 = fadd <vscale x 2 x float> %i65, %i66
  %i68 = fcmp ult <vscale x 2 x float> %i67, %i57
  %i74 = select <vscale x 2 x i1> %i63, <vscale x 2 x i1> %i68, <vscale x 2 x i1> zeroinitializer
  %i75 = select <vscale x 2 x i1> %i74, <vscale x 2 x i64> zeroinitializer, <vscale x 2 x i64> %i42
  %i76 = select <vscale x 2 x i1> %i63, <vscale x 2 x i64> %i75, <vscale x 2 x i64> zeroinitializer
  %i77 = add <vscale x 2 x i64> %i54, %i76
  %i116 = tail call i64 @llvm.vector.reduce.add.nxv2i64(<vscale x 2 x i64> %i77)
  ret i64 %i116
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <vscale x 2 x i32> @llvm.smax.nxv2i32(<vscale x 2 x i32>, <vscale x 2 x i32>) #0

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <vscale x 2 x i32> @llvm.smin.nxv2i32(<vscale x 2 x i32>, <vscale x 2 x i32>) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: read)
declare <vscale x 2 x float> @llvm.masked.load.nxv2f32.p0(ptr nocapture, i32 immarg, <vscale x 2 x i1>, <vscale x 2 x float>) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(read)
declare <vscale x 2 x float> @llvm.masked.gather.nxv2f32.nxv2p0(<vscale x 2 x ptr>, i32 immarg, <vscale x 2 x i1>, <vscale x 2 x float>) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.vector.reduce.add.nxv2i64(<vscale x 2 x i64>) #3

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: read) }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(read) }
attributes #3 = { nocallback nofree nosync nounwind willreturn memory(none) }
